package com.my.config;

import java.util.Properties;

import org.apache.velocity.app.VelocityEngine;
import org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.my.toolkit.template.TemplateUtil;
import com.my.toolkit.template.TrimAllDirective;

/**
 * 
 * @author wangym
 * @date 2016年5月2日
 * 
 */
@Configuration
public class TemplateConfig {

	public static final String ENCODING="UTF-8";
	public static final String TEMPLATE="/templates";
	public static final String LOG="/log/velocity.log";
	
	@Bean
	public TemplateUtil templateUtil() {
		VelocityEngine velocityEngine = new VelocityEngine();
		Properties p = new Properties();
		p.setProperty("file.resource.loader.class", ClasspathResourceLoader.class.getName());
		p.setProperty("userdirective", TrimAllDirective.class.getName());
		p.setProperty("input.encoding", ENCODING);
		p.setProperty("output.encoding", ENCODING);
		p.setProperty("runtime.log", LOG);
		velocityEngine.init(p);
		return new TemplateUtil(velocityEngine,TEMPLATE);
	}
}
